package com.myPlaneGame.obj;

import com.myPlaneGame.GameCreate;
import com.myPlaneGame.Utils.GameUtils;

import java.awt.*;

import static com.myPlaneGame.Utils.GameUtils.littleBoss2List;

public class LittleBoss2 extends GameObj{
    //定义一个血量属性
    int health=100;
    public LittleBoss2() {
        super();
    }

    public LittleBoss2(Image img, int width, int height, int x, int y, double speed, GameCreate frame) {
        super(img, width, height, x, y, speed, frame);
    }

    public LittleBoss2(Image img, int x, int y, double speed) {
        super(img, x, y, speed);
    }

    public LittleBoss2(int x, int y) {
        super(x, y);
    }

    @Override
    public void paintSelf(Graphics g) {
        super.paintSelf(g);
        if(y<150){
            y+=2;
        }else {
            x+=speed;
            //boss2在窗口进行左右移动直到被消灭
            if(x>400||x<10){
                speed=-speed;
            }
        }

        //1.敌方boss2和我方一级子弹碰撞后，我方子弹消失(boss2血量为0就消失)
        for (ShellObj shellObj : GameUtils.shellObjList) {
            if (this.getRec().intersects(shellObj.getRec()) && health > 0) {
                shellObj.setX(-100);
                shellObj.setY(-100);
                GameUtils.removeList.add(shellObj);
                health--;
            } else if (this.getRec().intersects(shellObj.getRec())) {
                //boss2生命值为0之后出现爆炸动画
                ExplodeObj explodeObj = new ExplodeObj(x, y);
                GameUtils.explodeObjList.add(explodeObj);
                GameUtils.removeList.add(explodeObj);

                //当敌方小boss被击毁的时候才会出现补给品
                GiftObj giftObj=new GiftObj(x,y);
                GameUtils.giftObjList.add(giftObj);
                GameUtils.gameObjList.addAll(GameUtils.giftObjList);

                shellObj.setX(-100);
                shellObj.setY(-100);
                this.x = -200;
                this.y = -200;
                GameUtils.removeList.add(this);
                GameUtils.littleBoss2List.remove(this);
                GameCreate.score+=20;
            }
        }
        //2.敌方boss2和我方二级子弹碰撞后，我方子弹消失(boss2血量为0就消失)
        for (DoubleShellObj doubleShellObj : GameUtils.doubleShellObjList) {
            if (this.getRec().intersects(doubleShellObj.getRec()) && health > 0) {
                doubleShellObj.setX(-100);
                doubleShellObj.setY(-100);
                GameUtils.removeList.add(doubleShellObj);
                health-=2;
            } else if (this.getRec().intersects(doubleShellObj.getRec())) {
                //boss2生命值为0之后出现爆炸动画
                ExplodeObj explodeObj = new ExplodeObj(x, y);
                GameUtils.explodeObjList.add(explodeObj);
                GameUtils.removeList.add(explodeObj);

                if (PlaneObj.times<2) {
                    //当敌方小boss被击毁的时候才会出现补给品
                    GiftObj giftObj=new GiftObj(x,y);
                    GameUtils.giftObjList.add(giftObj);
                    GameUtils.gameObjList.addAll(GameUtils.giftObjList);
                }

                doubleShellObj.setX(-100);
                doubleShellObj.setY(-100);
                this.x = -200;
                this.y = -200;
                GameUtils.removeList.add(this);
                GameUtils.littleBoss2List.remove(this);
                GameCreate.score+=20;

            }
        }
        //3.敌方boss2和我方三级子弹碰撞后，我方子弹消失(boss2血量为0就消失)
        for (TripleShellObj tripleShellObj : GameUtils.tripleShellObjList) {
            if (this.getRec().intersects(tripleShellObj.getRec()) && health > 0) {
                tripleShellObj.setX(-100);
                tripleShellObj.setY(-100);
                GameUtils.removeList.add(tripleShellObj);
                health-=5;
            } else if (this.getRec().intersects(tripleShellObj.getRec())) {
                //boss2生命值为0之后出现爆炸动画
                ExplodeObj explodeObj = new ExplodeObj(x, y);
                GameUtils.explodeObjList.add(explodeObj);
                GameUtils.removeList.add(explodeObj);

                if (PlaneObj.times<2) {
                    //当敌方小boss被击毁的时候才会出现补给品(可以是增强子弹威力)（可以是加飞机血量(待完善)）
                    GiftObj giftObj=new GiftObj(x,y);
                    GameUtils.giftObjList.add(giftObj);
                    GameUtils.gameObjList.addAll(GameUtils.giftObjList);
                }

                tripleShellObj.setX(-100);
                tripleShellObj.setY(-100);
                this.x = -200;
                this.y = -200;
                GameUtils.removeList.add(this);
                GameUtils.littleBoss2List.remove(this);
                GameCreate.score+=20;
            }
        }
        //重新刷新游戏数据
        if(GameCreate.state==3||GameCreate.state==4){
            this.x=-1000;
            this.y=-1000;
            GameUtils.removeList.add(this);
        }
    }

    @Override
    public Rectangle getRec() {
        return super.getRec();
    }
}
